﻿using System;
using UnityEngine;

namespace JH
{
    public static class CalcGameObjectScreenPositionRealization
    {
        /// <summary>
        /// 计算物体的屏幕空间坐标
        /// </summary>
        public static Vector3 CalcScreenPositionEm(this GameObject go, Camera renderCamera)
        {
            if (go == null)
                throw new ArgumentNullException(nameof(go),
                    "必须传入一个物体，才能计算物体的屏幕空间坐标");
            if (renderCamera == null)
                throw new ArgumentNullException(nameof(renderCamera),
                    "必须传入一个相机，才能计算物体的屏幕空间坐标");

            return renderCamera.WorldToScreenPoint(go.transform.position);
        }
    }
}